package com.dx.architectureddd.adapter.web;

import com.dx.architectureddd.api.dto.req.FinishCmd;
import com.dx.architectureddd.app.executor.FinishCmdExe;
import com.dx.architectureddd.app.executor.InitCmdExe;
import com.dx.architectureddd.domain.FlowNodeContext;
import org.apache.commons.lang3.ObjectUtils;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * 控制器
 *
 * @author xin.deng
 * @date 2023/10/05
 */
@RestController
public class LiteFlowController {

    @Resource
    private InitCmdExe initCmdExe;

    @Resource
    private FinishCmdExe finishCmdExe;

    @GetMapping("/start/{level}")
    public String init(@PathVariable("level") String level) {
        FinishCmd finishCmd = initCmdExe.execute(level);
        if (ObjectUtils.isEmpty(finishCmd)) {
            return "代码错误";
        }
        FlowNodeContext flowNodeContext = finishCmdExe.execute(finishCmd);
        if (flowNodeContext.getReward() != null && flowNodeContext.getUuid() != null) {
            return flowNodeContext.getReward() + "，特殊奖励兑换码：" + flowNodeContext.getUuid();
        } else if (flowNodeContext.getReward() != null) {
            return flowNodeContext.getReward();
        } else {
            return "副本等级过高，通关失败，当前副本等级为：" + flowNodeContext.getCurLevel();
        }
    }
}
